-
Notifications
You must be signed in to change notification settings - Fork 613
Disabled remote-debugging by default and appshell.app.getRemoteDebuggingPort() needs a callback argument to work #668
Disabled remote-debugging by default and appshell.app.getRemoteDebuggingPort() needs a callback argument to work #668
Conversation
g-217
commented
Nov 6, 2019
- Disabling remote debugging by default, and it can be enabled by passing a command line arg as --remote-debugging-port=xxxx
- Changed appshell.app.getRemoteDebuggingPort() implementation to require a callback
- Added validation for port range, and also without remote-debugging-port we will not be able to debug brackets using a browser, and if browser debugging is disabled, appshell.app.getRemoteDebuggingPort(callback) will print 0
…ingPort() needs a callback argument to work
appshell/cefclient.cpp
Outdated
CefString debugger_port = command_line->GetSwitchValue("remote-debugging-port"); | ||
if (!debugger_port.empty()) { | ||
int port = atoi(debugger_port.ToString().c_str()); | ||
static const int max_port_num = static_cast<int>(std::numeric_limits<uint16_t>::max()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if the port is already in use?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked with python -m SimpleHTTPServer 9999
and Brackets snatches the port from Python HTTP Server.
@@ -842,6 +842,8 @@ class ProcessMessageDelegate : public ClientHandler::ProcessMessageDelegate { | |||
uberDict->SetList(0, dirContents); | |||
uberDict->SetList(1, allStats); | |||
responseArgs->SetList(2, uberDict); | |||
} else if (message_name == "GetRemoteDebuggingPort") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're changing the normal function to one that takes callback? Does this have any impact on existing usages? This is a breaking change, though I guess no extensions will ideally use this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it does impact one use case, and fixed that with commit: adobe/brackets@8677756
appshell/cefclient.cpp
Outdated
CefString debugger_port = command_line->GetSwitchValue("remote-debugging-port"); | ||
if (!debugger_port.empty()) { | ||
int port = atoi(debugger_port.ToString().c_str()); | ||
static const int max_port_num = static_cast<int>(std::numeric_limits<uint16_t>::max()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we get away without needing limits header?
I am not comfortable with the need for unsetting standard functions.
You can compute uint16 max as such, which will work for all platforms
uint16_t max_limit = 0;
max_limit = ~max_limit;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::numeric_limits<> is C++ equivalent of C macros denoting MAX and MIN of a default numeric data types. So, instead of std::numeric_limits<uint16_t>::max()
, I could use UINT16_MAX
defined in stdint.h
uint16 max_limit = 0;
max_limit = ~max_limit;
max_limit = max_limit >> 1
Bitwise gymnastics suggested above is unnecessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't bother about header, it's C++, not JS.
Addressed all the review comments. |
@vickramdhawal Can you please take a quick look? |
appshell/config.h
Outdated
@@ -82,7 +82,7 @@ | |||
|
|||
#endif | |||
|
|||
#define REMOTE_DEBUGGING_PORT 9234 | |||
extern int g_remote_debugging_port; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this needed here ? use it in appshell_extensions.cpp
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@@ -19,6 +19,7 @@ | |||
#include "config.h" | |||
|
|||
CefRefPtr<ClientHandler> g_handler; | |||
int g_remote_debugging_port = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use unsigned int.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since, we are going to use atom or strtol further, as suggested by you using int is better for comparisons.
appshell/cefclient.cpp
Outdated
static const int max_port_num = 65535; | ||
static const int max_reserved_port_num = 1024; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use unsigned int.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using strtol
for integer parsing, so moved to signed long
.
appshell/cefclient.cpp
Outdated
settings.remote_debugging_port = REMOTE_DEBUGGING_PORT; | ||
CefString debugger_port = command_line->GetSwitchValue("remote-debugging-port"); | ||
if (!debugger_port.empty()) { | ||
int port = atoi(debugger_port.ToString().c_str()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using atoi seems acceptable in this case since the string is coming from the CommandLine handler. Better would be to use strtol.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed parsing to use strtol
.
…e to use g_handler to hold remote-debugging-port as g_handler does not get initialized while we are parsing command line
@vickramdhawal Addressed review comments. It is not possible to use |
appshell/cefclient.cpp
Outdated
LOG(ERROR) << "Error while parsing remote-debugging-port arg: "<< debugger_port.ToString(); | ||
errno = 0; | ||
} | ||
static const long max_port_num = 65535; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all of this should then be in the else case if errno is not ERANGE, since we know the port was not parsed properly and comparisons further may not give desired results.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM :+1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
…ingPort() needs a callback argument to work (adobe#668) * Disabled remote-debugging by default and appshell.app.getRemoteDebuggingPort() needs a callback argument to work * Addressing review comments * Addressing review comments * Updating error meesage for port validation * Addressing review comments from vickramdhawal, also it is not possible to use g_handler to hold remote-debugging-port as g_handler does not get initialized while we are parsing command line * More error message correction